/*
 * Filename AlgoService.java 2021年09月26日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author wuyingchao
 */
package com.ehome.poct.core.service;

import com.ehome.poct.core.factory.CheckDataFactory;
import com.ehome.poct.core.api.dto.check.AlgoRequestLog;
import com.ehome.poct.core.api.dto.check.CellAlgoAnalysisDTO;
import com.ehome.poct.core.api.virtual.AlgoService;
import com.ehome.poct.core.repository.check.AlgoRequestLogRepository;
import com.ehome.poct.core.service.rpc.CellAlgoRpc;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 算法 service
 *
 * @author cq
 * @since 2021/09/26 17:40
 **/
@AllArgsConstructor
@Service
public class CellAlgoServiceImpl  implements AlgoService {
    private final CellAlgoRpc algoRpc;
    private final AlgoRequestLogRepository algoReqLogRepo;

    /**
     * 算法调用
     * @param dto
     * @return
     */
    @Override
    public AlgoRequestLog callAlgo(CellAlgoAnalysisDTO dto) {
        final var response = algoRpc.analyse(dto);

        final var algoReqLog = CheckDataFactory.createAlgoRequestLog(response.get(0), dto,
                response.get(1), dto.getDeviceId(), dto.getPath());
        // 记录调用日志
        algoReqLogRepo.save(algoReqLog);
        return algoReqLog;
    }

}